<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>await</title>
  </head>
  <body>
    <script>
      // 创建Promise对象
      const p = new Promise((resolve, reject) => {
        // resolve("用户数据");
        reject("失败了");
      });

      // await 要放在 async 函数中
      async function main() {
        // Promise 失败使用 try...catch进行错误捕获
        try {
          // await 返回Promise成功的值
          let result = await p;
          console.log(result);
        } catch (e) {
          console.log(e);
        }
      }

      // 调用函数main
      main();
    </script>
  </body>
</html>
